package com.it.commicity.config.exception;

import com.it.commicity.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class WebExceptionAdvice {

    @ExceptionHandler(RuntimeException.class)
    public Result handleRuntimeException(RuntimeException e) {
        log.error(e.toString(), e);
        return Result.fail("服务器异常");
    }

    @ExceptionHandler(TokenException.class)
    public Result handleSmsException(TokenException e) {
        log.error(e.toString(), e);
        return Result.fail(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(SmsException.class)
    public Result handleSmsException(SmsException e) {
        log.error(e.toString(), e);
        return Result.fail(e.getCode(), e.getMessage());
    }

    @ExceptionHandler(ExcelException.class)
    public Result ExcelException(ExcelException e) {
        log.error(e.toString(), e);
        return Result.fail(e.getCode(), e.getMessage());
    }
}
